package cn.e4j.modular.crm.controller.base;

import cn.e4j.core.base.controller.BaseController;
import cn.e4j.core.common.exception.BizExceptionEnum;
import cn.e4j.core.dto.impl.Dto;
import cn.e4j.core.dto.requestDtoResolver.DtoParam;
import cn.e4j.core.dto.requestDtoResolver.DtoWapper;
import cn.e4j.core.reqres.response.ErrorResponseData;
import cn.e4j.core.reqres.response.PageReData;
import cn.e4j.core.reqres.response.ResponseData;
import cn.e4j.modular.crm.entity.MmrjT;
import cn.e4j.modular.crm.entity.MmrjlT;
import cn.e4j.modular.crm.service.MmrjTService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * 标准评价指标维护 控制层
 * @author mengyb
 * @date 2019-04-16
 */
@Controller
@RequestMapping("/base/gwai650")
public class Gwai650Controller extends BaseController {

    @Autowired
    private MmrjTService mmrjTService;

    /**
     * 跳转至标准评价指标维护主界面
     * @return
     */
    @RequiresPermissions("base:gwai650:init")
    @RequestMapping(value = {"","init"})
    public String index(){
        return "/pc/crm/base/gwai650.html";
    }

    @RequiresPermissions("base:gwai650:init")
    @RequestMapping("/getList")
    @ResponseBody
    public ResponseData getList(@DtoParam DtoWapper dtoWapper) {
        Dto inDto = dtoWapper.getDto();
        Page<Object> page=dtoWapper.getPage();
        List<Map<String, Object>> list = mmrjTService.getList(inDto, page);
        return new PageReData<>(page,list);
    }

    @RequiresPermissions("base:gwai650:init")
    @RequestMapping("/add")
    @ResponseBody
    public ResponseData add(MmrjT mmrjT, MmrjlT mmrjlT) {
        if(mmrjTService.existedTheParams(mmrjT)){
            return new ErrorResponseData(BizExceptionEnum.EXISTED_THE_PARAMS.getCode(),
                    BizExceptionEnum.EXISTED_THE_PARAMS.getMessage());
        }
        mmrjTService.add(mmrjT, mmrjlT);
        return SUCCESS_TIP;
    }

    @RequiresPermissions("base:gwai650:init")
    @RequestMapping("/edit")
    @ResponseBody
    public ResponseData edit(MmrjT mmrjT, MmrjlT mmrjlT) {
        mmrjTService.edit(mmrjT, mmrjlT);
        return SUCCESS_TIP;
    }

    @RequiresPermissions("base:gwai650:init")
    @RequestMapping("/delRow")
    @ResponseBody
    public ResponseData delRow(MmrjT mmrjT, MmrjlT mmrjlT) {
        mmrjTService.delRow(mmrjT, mmrjlT);
        return SUCCESS_TIP;
    }

    @RequiresPermissions("base:gwai650:init")
    @RequestMapping("/delRows")
    @ResponseBody
    public ResponseData delRows(@DtoParam DtoWapper dtoWapper) {
        Dto inDto = dtoWapper.getDto();
        List<MmrjT> mmrjTList = inDto.getReqList(MmrjT.class);
        mmrjTService.delRows(mmrjTList);
        return SUCCESS_TIP;
    }

}
